/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package py.una.informatica.facades;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import py.una.informatica.entidades.Doctor;

/**
 *
 * @author MARTINCHO
 */
@Stateless
public class DoctorFacade extends AbstractFacade<Doctor> {

    @PersistenceContext(unitName = "py.com.konecta_EmergenciasEJB_ejb_1.0-SNAPSHOTPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public DoctorFacade() {
        super(Doctor.class);
    }

    public Doctor getDoctorById(Long idDoctor) {
        Doctor per = null;
        try {
            getEntityManager().getEntityManagerFactory().getCache().evictAll();
            TypedQuery<Doctor> query = getEntityManager().createNamedQuery("Doctor.findByIdDoctor", Doctor.class);
            per = query.setParameter("idDoctor", idDoctor).getSingleResult();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return per;
    }
    
    public Doctor getDoctorByCedula(Integer cedula) {
        Doctor per = null;
        try {
            getEntityManager().getEntityManagerFactory().getCache().evictAll();
            TypedQuery<Doctor> query = getEntityManager().createNamedQuery("Doctor.findByNumDoc", Doctor.class);
            per = query.setParameter("numDoc", cedula).getSingleResult();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return per;
    }
    
    
}
